<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('信科委审核')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-audit">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">审批时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input id="approvalTime" name="approvalTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">审批结果：</label>
                <div class="col-sm-8">
                    <label class="radio-box"><input type="radio" checked="" value="true" name="informationAuditApprove">同意</label>
                    <label class="radio-box"><input type="radio" value="false" name="informationAuditApprove">拒绝</label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">审批意见：</label>
                <div class="col-sm-8">
                    <textarea rows="5" name="comment" class="form-control"></textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">相关文件：</label>
                <div class="col-sm-8 ">
                    <input id="multipleFile" class="form-control" name="files" type="file" multiple>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">经办人：</label>
                <div class="col-sm-8">
                    <input id="createBy" name="createBy" class="form-control" type="text" th:value="${createBy}" readonly>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-6 col-sm-offset-3">
                    <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                    <input type="hidden"  name="projectId" id="projectId" th:value="${projectId}">
                    <input type="hidden"  name="scheduleId" id="scheduleId" th:value="${scheduleId}">
                    <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                    <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script th:inline="javascript">

    var prefix = ctx + "task/manage";
    var filePrefix = ctx + "project/file";

    $("#form-audit").validate({
        focusCleanup: true
    });

    function saveActiviti(dataParam) {
        var json = { "informationAuditApprove": dataParam.informationAuditApprove, "comment": dataParam.comment};
        $.operate.saveActiviti(prefix + "/completeTask/" + dataParam.taskid, "application/json;charset=UTF-8", JSON.stringify(json));
    }

    function submitHandler() {
        if ($.validate.form()) {
            $.modal.loading("正在处理中，请稍候...");
            $("#multipleFile").fileinput('upload');
        }
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });

        <!-- laydate示例 -->
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            laydate.render({
                elem: '#approvalTime',
                value: $.common.dateFormat(new Date()),
                isInitValue: true
            });
        });

        // 多文件上传
        $("#multipleFile").fileinput({
            //是否显示被选文件的简介
            showCaption: true,
            //是否显示上传按钮
            showUpload: false,
            //是否显示拖拽区域
            dropZoneEnabled: false,
            uploadUrl: filePrefix + '/uploads',
            allowedFileExtensions: ['doc', 'docx', 'pdf'],
            uploadAsync: false,
            validateInitialCount: true,
            maxFileSize: 10240,
            maxFileCount: 10,
            enctype: 'multipart/form-data',
            layoutTemplates: {
                //去除上传
                actionUpload: ''
            },
            uploadExtraData: function () {
                return $.common.formToJSON("form-audit");
            }
        }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
            if (data.response.code == web_status.SUCCESS) {
                saveActiviti($.common.formToJSON("form-audit"));
            } else {
                $(event.target).fileinput('clear').fileinput('unlock');
                $(event.target).parent().siblings('.fileinput-remove').hide();
                $.modal.closeLoading();
                $.modal.msgError("保存失败");
            }
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    });
</script>
</body>
</html>